<?php 
## include required files
/*******************************/
require_once '../model/membershipplan.php';
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/

## Create Objects
/*******************************/
$planObj = new Model_PLAN();
$moduleObj=new Model_ModuleUser();
/*******************************/

/*******************************/
if($_GET['q']=='plan')
{
	$moduelArray=$moduleObj->getModuleHelpText(11);
	$smarty->assign('moduelArray', $moduelArray);
	//echo '<pre>';print_r($moduelArray);exit;
}
##Fetch all cms pages from database
## Get search parameters in variables - 
if($_POST['search'] != '' && $_POST['search'] != 'Plan name') {
	$searchindex = addslashes($_POST['search']);
} else if($_GET['search'] != '') {
	$searchindex = addslashes($_GET['search']);
} else {
	$searchindex = '';
}
$searchindex=trim($searchindex);
$smarty->assign('search', stripslashes (stripslashes ($searchindex)));

if($_GET['col1'] != '') {
	$col1 = base64_decode($_GET['col1']);
}
else if($_GET['col2'] != '') 
{
	$col2 = base64_decode($_GET['col2']);
} 

##  --------- Pagination part first start --------------##
	if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] != "" ) {
		$pageNum = $_GET[ 'page' ];
	} else {
		$pageNum = 1;
	} 
	$rowsPerPage = ROW_PER_PAGE;
	if($_GET['col1'] != '') {
		$pageName = "home.php?q=plan&col1=".$_GET['col1'].""; 
	} 
	else if($_GET['col2'] != '') 
	{
		$pageName = "home.php?q=plan&col2=".$_GET['col2'].""; ;
	} 
	else {
		$pageName = "home.php?q=plan"; 	
	}
	## Count all the records
	$planArray = $planObj->getAllPlan($searchindex,$col1,$col2);
	$total_rows = count($planArray);
	$offset	= ($pageNum - 1) * $rowsPerPage;
	$smarty->assign('page', $pageNum);
##  --------- Pagination part first end --------------##


##  --------- Pagination part second start --------------##
	$newid = $pageNum * $rowsPerPage - $rowsPerPage + 1;
	$smarty->assign('newid', $newid);
	$planArray = $planObj->getAllPlan($searchindex,$col1,$col2,$rowsPerPage,$offset);
	//echo "<pre>"; print_r($planArray);exit;
	$smarty->assign('planArray', $planArray);
	if($total_rows > ROW_PER_PAGE) {
		$pg = new pagination();					// CREATING OBJECT OF THE PAGINATION CLASS
		$pgnation = $pg->pagination_admin( $total_rows , $rowsPerPage , $pageNum , $pageName , $other_id, $class);	
		$smarty-> assign("pagination",$pgnation);
	}
##  --------- Pagination part second end --------------##	

## Assign session message to smarty variable and unset session variable
if($_SESSION['msg'] != '') {
	$smarty->assign('msg', $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

## Set active class variable for left menu (main menu and sub menu)
$smarty->assign('activeclass', 'membershipplan');
$smarty->assign('mainmenu', '2');

## Unset all the objects created which are on this page
unset($planObj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'membershipplan/plan.tpl');
unset($smarty);
?>